#include "Lamp.h"
void Lamp::executeCommand(const std::string& command) {
    std::lock_guard<std::mutex> lock(deviceMutex);
    Json::Value cmd;
    Json::Reader().parse(command, cmd);
    
    if(cmd.isMember("power")) {
        powerState = cmd["power"].asBool();
        Logger::log("Lamp " + std::to_string(id) + " power: " + 
                   (powerState ? "ON" : "OFF"));
    }
    
    if(cmd.isMember("brightness")) {
        int val = cmd["brightness"].asInt();
        brightness = std::clamp(val, 0, 100);
        Logger::log("Lamp " + std::to_string(id) + 
                   " brightness set to " + std::to_string(brightness) + "%");
    }
    
    updateTimestamp();
}
std::string Lamp::getStatus() const {
    Json::Value status;
    status["type"] = "Lamp";
    status["power"] = powerState;
    status["brightness"] = brightness;
    return Json::FastWriter().write(status);
}